#include "Timer1.h"
	/*variabeles*/
volatile unsigned long current_time=0x00000000;

void __attribute__ ((interrupt, auto_psv))  _T1Interrupt(void)
{
	current_time++;
	IFS0bits.T1IF = 0;
}

void InitTimer1(void)
{
	T1CON=0;						//Stops the Timer1 and reset control reg
	TMR1 = 0;  						//Clear contents of the timer register
	T1CONbits.TCKPS = 0x00; 		//prescaler x8
	PR1= 32760;					//Load the Period register
	IFS0bits.T1IF	= 0;            /* Clear Timer1 Interrupt Flag */
	IPC0bits.T1IP	= 4;            /* Set Timer1 Interrupt Priority */
	IEC0bits.T1IE	= 1;            /* Enable Timer1 Interrupt */	
	T1CONbits.TON 	= 1; 			// set timer on
	
}

unsigned long GetTime(void)
{
	volatile unsigned int flipflop=0;
	unsigned long gotten_time;
	while(flipflop==0)
	{
		while(IFS0bits.T1IF==0)
		{
			
			gotten_time=current_time;
			flipflop=1;
		}
	}
	return gotten_time;	
}

unsigned long GetTimeDifference( unsigned long time)
{
	return GetTime() - time;
}
